<%@ include file="/en/jsp/static.jsp" %>
<%@ page import="java.util.*,linuxbox.reservation.logic.*,linuxbox.resource.logic.*, linuxbox.util.StringUtil" %>

<%@ taglib uri="/linuxbox/common.tld" prefix="common" %>


<%
  int ID = Integer.parseInt((String)request.getAttribute("ID"));
  String SUBJECT = (String)request.getAttribute("SUBJECT");
  int RESOURCEID = Integer.parseInt((String)request.getAttribute("RESOURCEID"));
  int ISALLDAY = Integer.parseInt((String)request.getAttribute("ISALLDAY"));
  int FROM_YEAR = Integer.parseInt((String)request.getAttribute("FROM_YEAR"));
  int FROM_MONTH = Integer.parseInt((String)request.getAttribute("FROM_MONTH"));
  int FROM_DAY = Integer.parseInt((String)request.getAttribute("FROM_DAY"));
  int FROM_HOUR = Integer.parseInt((String)request.getAttribute("FROM_HOUR"));
  int FROM_MINUTE = Integer.parseInt((String)request.getAttribute("FROM_MINUTE"));
  int TO_HOUR = Integer.parseInt((String)request.getAttribute("TO_HOUR"));
  int TO_MINUTE = Integer.parseInt((String)request.getAttribute("TO_MINUTE"));
  Calendar tmpDate = Calendar.getInstance(sec.getTimeZone());
  tmpDate.set(FROM_YEAR, FROM_MONTH, FROM_DAY, FROM_HOUR, FROM_MINUTE, 0);
  long EDIT_DATE = tmpDate.getTime().getTime();
  String FROMDATE = StringUtil.getDateTimeFormatString(sec.getTimeZone(), BoxStatic.LONG_DATE_FORMAT, tmpDate.getTime());
  String FROMTIME = StringUtil.getDateTimeFormatString(sec.getTimeZone(), BoxStatic.SHORT_TIME_FORMAT, tmpDate.getTime());
  tmpDate.set(Calendar.HOUR, TO_HOUR);
  tmpDate.set(Calendar.MINUTE, TO_MINUTE);
  String TOTIME = StringUtil.getDateTimeFormatString(sec.getTimeZone(), BoxStatic.SHORT_TIME_FORMAT, tmpDate.getTime());

  String DESCRIPTION = (String)request.getAttribute("DESCRIPTION");
  int REPEAT_TYPE = Integer.parseInt((String)request.getAttribute("REPEAT_TYPE"));
  int REPEAT_EVERYWEEK = Integer.parseInt((String)request.getAttribute("REPEAT_EVERYWEEK"));
  int REPEAT_WEEKDAYS = Integer.parseInt((String)request.getAttribute("REPEAT_WEEKDAYS"));
  int REPEAT_WHICHWEEK = Integer.parseInt((String)request.getAttribute("REPEAT_WHICHWEEK"));
  int REPEAT_WHICHWEEKDAY = Integer.parseInt((String)request.getAttribute("REPEAT_WHICHWEEKDAY"));
  int REPEAT_EVERYMONTH = Integer.parseInt((String)request.getAttribute("REPEAT_EVERYMONTH"));

//  int REPEAT_FOREVER = Integer.parseInt((String)request.getAttribute("REPEAT_FOREVER"));
  int UNTIL_YEAR = Integer.parseInt((String)request.getAttribute("UNTIL_YEAR"));
  int UNTIL_MONTH = Integer.parseInt((String)request.getAttribute("UNTIL_MONTH"));
  int UNTIL_DAY = Integer.parseInt((String)request.getAttribute("UNTIL_DAY"));
  tmpDate.set(Calendar.YEAR, UNTIL_YEAR);
  tmpDate.set(Calendar.MONTH, UNTIL_MONTH);
  tmpDate.set(Calendar.DATE, UNTIL_DAY);

  String UNTILDATE = StringUtil.getDateTimeFormatString(sec.getTimeZone(), BoxStatic.LONG_DATE_FORMAT, tmpDate.getTime());

  if (REPEAT_TYPE!=0)
  {
    Calendar currentDate = (Calendar)session.getAttribute("currentDate");
    if (currentDate == null)
      EDIT_DATE = Calendar.getInstance(sec.getTimeZone()).getTime().getTime();
    else
      EDIT_DATE = currentDate.getTime().getTime();
  }

  String RESOURCENAME = null;
  if (ID!=0)
  {
    BoxResource resourceHome = new BoxResource();
    BoxResourceEntry resourceEntry = resourceHome.get(new linuxbox.bean.BaseIntKey(RESOURCEID));
    RESOURCENAME = resourceEntry.getName();
  }
  else
    RESOURCENAME = new String();
%>

<jsp:include page="/en/jsp/header.jsp" flush="true"/>

<form method="POST" name="theForm" action="<%=BoxStatic.servletDir%>BoxReservationAction">

<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
<tr><td>
    &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
    <b><%=boxName%> - Resource Reservation View</b>
</td></tr>
</table>

<hr width="100%" color=#E06000 align=left>

<table cellpadding="0" cellspacing="0" border="0" width="100%">
  <tr>
    <td nowrap align="left">
      <font size="-1" face="Arial,Helvetica">
       <input type=button value="Close" onclick="window.history.go(-1)" >
     </font>
    </td>
  </tr>
  <tr>
    <td>
      <table cellpadding="0" cellspacing="0" border="0" width="100%">
        <tr>
          <td>
            <b>Resource:</b> <%=RESOURCENAME%>
          </td>
        </tr>
        <tr>
          <td valign="top" nowrap><font size="-1" face="Arial,Helvetica"><b>Subject:</b></font>
            <%=SUBJECT%>
          </td>
        </tr>
        <tr>
          <td valign="top" nowrap>
            <b>Date:</b>&nbsp;<%=FROMDATE%>
              <b>&nbsp;&nbsp;
                      <%
                        if (ISALLDAY ==0)
                        {
                          out.print("From: </b>");
                          out.print(FROMTIME);
                          out.print("<b>     To: </b>");
                          out.print(TOTIME);
                        }
                        else
                        {
                          out.print("<b>All day</b>");
                        }
                      %>
          </td>
        </tr>
          <td valign="top" nowrap>
              <b>Description:</b><br>
                <textarea name="DESCRIPTION" rows="4" wrap="virtual" cols="60"><%=DESCRIPTION%></textarea>
          </td>
        </tr>
      </table>
    </td>
  </tr>
<%
  if (REPEAT_TYPE != 0 )
  {
%>
  <tr>
    <td>

<%
  StringBuffer strBuf = new StringBuffer();
  if (REPEAT_TYPE == 1 )
  {
    strBuf.append("Repeat every ");
    strBuf.append(REPEAT_EVERYWEEK);
    if (REPEAT_EVERYWEEK>1)
      strBuf.append(" weeks on ");
    else
      strBuf.append(" week on ");
    boolean first = true;
    //1,2,4,8,16,32,64 = Sun,Mon,Tue,Wed,Thu,Fri,Sat
    int testDay = 1;
    for(int i = 1; i<=7; i++)
    {
      if (( REPEAT_WEEKDAYS & testDay) != 0)
      {
        if (!first)
        {
          strBuf.append(",");
        }
        strBuf.append(BoxStatic.shortWeekSymbols[i]);
        first = false;
      }
      testDay <<= 1;
    }
    out.println(strBuf.toString());
  }
  else if (REPEAT_TYPE == 2 )
  {
    strBuf.append("Repeat on the ");
    if (REPEAT_WHICHWEEK==1)
      strBuf.append("First ");
    else if (REPEAT_WHICHWEEK==2)
      strBuf.append("Second ");
    else if (REPEAT_WHICHWEEK==3)
      strBuf.append("Third ");
    else if (REPEAT_WHICHWEEK==4)
      strBuf.append("Fourth ");
    else if (REPEAT_WHICHWEEK==5)
      strBuf.append("Last ");
    int index = 0;
    while (REPEAT_WHICHWEEKDAY > 0)
    {
      index++;
      REPEAT_WHICHWEEKDAY >>= 1;
    }
    strBuf.append(BoxStatic.weekSymbols[index]);
    strBuf.append(" of every ");
    strBuf.append(REPEAT_EVERYMONTH);
    if (REPEAT_EVERYMONTH > 1)
      strBuf.append(" months");
    else
      strBuf.append(" month");

    out.println(strBuf.toString());
  }
  else if (REPEAT_TYPE == 3)
  {
    out.println("Repeat every month");
  }
  else if (REPEAT_TYPE == 4 )
    out.println("Repeat every year");
%>
    </TD>
  </TR>
  <TR>
    <TD VALIGN="top" NOWRAP COLSPAN="2">
        Repeat until&nbsp;<b><%=UNTILDATE%></b>
    </TD>
  </TR>
<%
}
%>
</table>

<hr width="100%" color=#E06000 align=left>

</form>
<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
